const SET_TOKEN = 'example/token/SET_TOKEN';
const SET_USER = 'example/token/SET_USER';
const SET_IMG_URL = 'example/token/SET_IMG_URL';
const LOGOUT = 'example/token/LOGOUT';

const initialState = {
  access_token: '',
  userInfo: null,
  imgUrl: '',
};

export default function (state = initialState, action = {}) {
  switch (action.type) {
    case SET_TOKEN: {
      return {
        ...state,
        access_token: action.param,
      };
    }
    case SET_USER: {
      return {
        ...state,
        userInfo: action.param,
      };
    }
    case SET_IMG_URL: {
      return {
        ...state,
        imgUrl: action.param,
      };
    }
    case LOGOUT: {
      return {
        access_token: '',
        userInfo: null,
        imgUrl:'',
      };
    }
    default:
      return state;
  }
}

export function setToken(param) {
  return {
    type: SET_TOKEN,
    param,
  };
}
export function setUserInfo(param) {
  return {
    type: SET_USER,
    param,
  };
}
export function setImgUrl(param) {
  return {
    type: SET_IMG_URL,
    param,
  };
}
